<template>
  <div>
    <el-form :model="queryParam" :inline=true style="display: flex">
      <el-form-item label="编码">
        <el-input v-model="queryParam.code" style="width:160px"/>
      </el-form-item>
      <el-form-item label="名称">
        <el-input v-model="queryParam.name" style="width:160px"/>
      </el-form-item>
      <el-form-item label="公司名">
        <el-input v-model="queryParam.companyName" style="width:160px"/>
      </el-form-item>
      <el-form-item label="主营业务">
        <el-input v-model="queryParam.mainBusiness" style="width:160px"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="queryPage">搜索</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="danger" @click="refreshStock">刷新基本信息</el-button>
      </el-form-item>
    </el-form>

    <el-table :data="tableData" stripe style="width: 100%">
      <el-table-column prop="id" label="序号" width="80"></el-table-column>
      <el-table-column prop="code" label="编码" width="70"></el-table-column>
      <el-table-column prop="name" label="名称" width="80"></el-table-column>
      <el-table-column prop="companyName" label="公司名" width="260"></el-table-column>
      <el-table-column prop="lastPriceUpdateTime" label="日期" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lastPriceUpdateTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="lastPrice" label="最新价" width="100"></el-table-column>
      <el-table-column prop="lastVolume" label="最新交易量" width="100"></el-table-column>
      <el-table-column prop="registerCapital" label="注册资本" width="140"></el-table-column>
      <el-table-column prop="mainBusiness" label="主营业务">
        <template slot-scope="scope">
          <div class="typeEnter">{{ scope.row.mainBusiness  | ellipsis }}</div>
        </template>
      </el-table-column>
      <el-table-column prop="businessScope" label="业务范围">
        <template slot-scope="scope">
          <div class="typeEnter">{{ scope.row.businessScope  | ellipsis }}</div>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="pageTotal>0"
      :total="pageTotal"
      :page.sync="queryParam.pageNum"
      :limit.sync="queryParam.pageSize"
      @pagination="queryPage"
    />
  </div>
</template>

<script>
import {ellipsis, parseTime} from '@/utils'

export default {
  data () {
    return {
      // 查询参数
      pageTotal: 0,
      queryParam: {
        code: '',
        name: '',
        companyName: '',
        mainBusiness: '',
        pageNum: 1,
        pageSize: 5
      },
      tableData: []
    }
  },
  mounted () {
    this.pageList()
  },
  methods: {
    parseTime,
    ellipsis,
    queryPage () {
      var _this = this
      _this.pageList()
    },
    pageList () {
      var _this = this
      this.$api.basePageList(_this.queryParam).then(res => {
        if (res.code === '00000') {
          _this.tableData = res.data.pageList
          _this.pageTotal = res.data.pageTotal
        } else {
          _this.$message(res.msg)
        }
      }).catch(e => {
        console.log('接口访问异常!')
      })
    },
    refreshStock() {
      let _this = this
      this.$api.refreshStockInfo().then(res => {
        if (res.code === '00000') {
          _this.$message("触发成功")
        } else {
          _this.$message(res.msg)
        }
      }).catch(e => {
        console.log('接口访问异常!')
      })
    }
  },
  filters: {
    ellipsis: (str) =>  ellipsis(str, 32)
  }
}
</script>
